import pandas as pd
import math


def convert_to_p(bmi,week):

    p = -4.4749-0.4762*week+0.7013*bmi+0.0144*week*week+0.0003*week*bmi-0.0121*bmi*bmi

    p = 1.0/(1+math.exp(-p))
    

    return p


if __name__ == "__main__":
    
    data = pd.read_excel("data_after_process.xlsx")
    data['p概率'] = data.apply(lambda row:convert_to_p(
        row['孕妇BMI'],
        row['检测孕周（小数）'],
    ),axis=1 )

    print(data)
    data.to_excel("data_after_q2.xlsx")

